﻿// /////////////////////////////////// 
//  
//  
//      WiseLink CCF2.0 
//     (c)Copyright 2001-2010 WiseLink Xiaojun (David) Chen 
//        Authored and Owned Xiaojun (David) Chen 
//        All Right Reserved
//  
// /////////////////////////////////// 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CCF20Model.ConfigurationFile
{
    public class CCFConnection : IConfiguration
    {

        private string ccfConnectionTemplate = "metadata=res://*/CCF20Model.csdl|res://*/CCF20Model.ssdl|res://*/CCF20Model.msl;" +
                                               "provider=System.Data.SqlClient;provider connection string=\'MultipleActiveResultSets=True;" +
                                               "Data Source={0};Initial Catalog={1};User Id={2};Password={3}\';";
        
        

        private IConfiguration _previousConfig;
        private string strResult = string.Empty;
        
        public CCFConnection(IConfiguration previousConfig)
        {
            _previousConfig = previousConfig;
        }

        public string VerifyResult()
        {
            WiseLinkConfiguration myConfig = ConfiguraitonHelper.MyConfiguration;
            string myConfigConnection = string.Format(ccfConnectionTemplate, myConfig.database, myConfig.catalog, myConfig.user, myConfig.password);

            string ccfConnection = ConfiguraitonHelper.GetConfigValueFromAppConfig(AppConfigFileName.CCF, AppConfigFileNodeName.CCF20Entities);

            if (!ccfConnection.Equals(myConfigConnection, StringComparison.OrdinalIgnoreCase))
            {
                ConfiguraitonHelper.SetConfigValueToAppConfig(AppConfigFileName.CCF, AppConfigFileNodeName.CCF20Entities, myConfigConnection);
                strResult = string.Format("CCF20 AppConfig File CCF20ConnectionString has different value than the config.xml\r\n{0}\r\n{1}",ccfConnection,myConfigConnection);
            }
         
            return string.Format("{0} \r\n{1}", _previousConfig.VerifyResult(), strResult);
        }

        
    }
}
